<template>
	<view class="page">
		<view class="plan-list">
			<view class="youjiantou">
				<view class="list-item jt">
					<view class="item-left">车辆信息</view>
					<view class="item-right">{{gouchedaiData.brand}} {{gouchedaiData.series}} {{gouchedaiData.vehicle_type}}</view>
				</view>
			</view>
		</view>
		<view class="plan-list">
			<view class="youjiantou">
				<view class="list-item jt">
					<view class="item-left">是否新能源</view>
					<view class="item-right">{{gouchedaiData.energy ? '是' : '否'}}</view>
				</view>
			</view>
			<view class="list-itemJe">
				<view class="item-top">
					<view class="item-top-left">成交金额</view>
					<view class="item-right">{{gouchedaiData.transaction_price}}元</view>
				</view>
			</view>
			<view v-if="gouchedaiData.biz_type == 9" class="list-item">
				<view class="item-left">附加贷金额</view>
				<view class="item-right">{{gouchedaiData.additionalAmt}}元</view>
			</view>
			<view class="youjiantou">
				<view class="list-item jt">
					<view class="item-left">首付方式</view>
					<view class="item-right">{{gouchedaiData.down_method}}</view>
				</view>
			</view>
			<view class="youjiantou" v-if="gouchedaiData.down_method == '按比例支付'">
				<view class="list-item jt">
					<view class="item-left">首付比例</view>
					<view class="item-right">{{gouchedaiData.down_ratio}}%</view>
				</view>
			</view>
			<view class="youjiantou" v-if="gouchedaiData.down_method == '按定额支付'">
				<view class="list-item jt">
					<view class="item-left">首付金额</view>
					<view class="item-right">{{gouchedaiData.down_amount}}元</view>
				</view>
			</view>
			<view class="youjiantou">
				<view class="list-item jt">
					<view class="item-left">贷款期数</view>
					<view class="item-right">{{gouchedaiData.periods}}</view>
				</view>
			</view>
			<block v-if="gouchedaiData.biz_type == 7">
				<view class="youjiantou">
					<view class="list-item jt">
						<view class="item-left">是否贴息</view>
						<view class="item-right">{{gouchedaiData.discount_status}}</view>
					</view>
				</view>
				<view class="youjiantou" v-if="gouchedaiData.discount_status == '是'">
					<view class="list-item jt">
						<view class="item-left">贴息方案</view>
						<view class="item-right">{{gouchedaiData.discount_name}}</view>
					</view>
				</view>
				</block>
				<view class="list-item">
					<view class="item-left">还款方式</view>
					<view class="item-right">等额本息，按月还款</view>
				</view>
				<view class="list-item">
					<view class="item-left">借款金额</view>
					<view class="item-right">{{(gouchedaiData.loan_amount*1).toFixed(2)}}元</view>
				</view>
		</view>

		<view class="prompt2">请确认以上信息无误后提交下一步！</view>
		<view class="btnBox2">
			<button class="btn" @click="change">修改</button>
			<button class="btn" @click="nextBtn">确认无误</button>
		</view>
	</view>
</template>

<script>
	import {getOrderLinshiByid, createOrder} from '@/service/chengyongche'
	let app = getApp();
	export default {
		data() {
			return {
				gouchedaiData: {},
				status: '',
				userInfoData: {},
				header: {}
			}
		},
		onLoad(e) {
			console.log(app.globalData.gouchedaiData)
			let gouchedaiData = {};
			let status = '';
			e.status ? status = e.status : status = '';
			status == 1 ? gouchedaiData = uni.getStorageSync('unfinished') : gouchedaiData = app.globalData.gouchedaiData;
			let id = gouchedaiData.searchId;
			let userInfoData = uni.getStorageSync('userInfo');
			let header = {
				'content-type': 'application/x-www-form-urlencoded',
				'Authorization': userInfoData.token
			};
			this.gouchedaiData = gouchedaiData;
			this.status = status;
			this.userInfoData = userInfoData;
			this.header = header;
			let prams = {id};
			this._getOrderLinshiByid(prams, header);
		},
		methods: {
			change() {
				console.log(this.status)
				uni.navigateTo({ url: '../confirmation2/confirmation2?status='+this.status });
			},
			nextBtn() {
				let gouchedaiData = this.gouchedaiData;
				let enterpiseId = gouchedaiData.enterprise_id, // 经销商id
					saleId = gouchedaiData.saleId,// 销售id
					sellName = gouchedaiData.sellName,// 销售姓名
					brandName = gouchedaiData.brand,// 品牌名称
					brandId = gouchedaiData.brandId,// 品牌id
					carTypeName = gouchedaiData.series,// 车系名称
					carTypeId = gouchedaiData.seriesId,// 车系id
					carName = gouchedaiData.vehicle_type,// 车型名称
					carId = gouchedaiData.vehicle_typeId,// 车型id
					logo = gouchedaiData.logo,// 品牌logo图片地址
					energy = gouchedaiData.energy,// 是否新能源（0-否，1-是）
					transaction_price = gouchedaiData.transaction_price,// 成交价
					down_method = gouchedaiData.down_method,// 首付方式
					down_ratio = gouchedaiData.down_ratio,// 首付比例
					down_amount = gouchedaiData.down_amount,// 首付金额
					periods = gouchedaiData.periods,// 期数
					discount_status = gouchedaiData.discount_status,//  是否贴息
					discount_name = gouchedaiData.discount_name,//  贴息方案
					sysUniqueNo = '',
					biz_type = gouchedaiData.biz_type,// 业务类型 
					repayment = '等额本息',// 还款方式（默认等额本息）
					loan_amount = gouchedaiData.loan_amount,// 借款金额
					additionalRate = gouchedaiData.additionalRate, //附加贷利率
					additionalAmt = gouchedaiData.additionalAmt; //附加贷金额
				discount_status == "是" ? sysUniqueNo = gouchedaiData.sysUniqueNo : sysUniqueNo = undefined
				discount_status == "是" ? discount_name = gouchedaiData.discount_name : discount_name = undefined
				if(down_method == "按比例支付") down_amount = undefined
				if(down_method == "按定额支付") down_ratio = undefined
				const siteUserId = this.userInfoData.mobile;
				let prams = {}
				if (biz_type == 7) prams = {siteUserId, enterpiseId, saleId, brandName, brandId, carTypeName, carTypeId, carName, carId, logo, energy, transaction_price, down_method, down_ratio, down_amount, periods: parseInt(periods), repayment, discount_status, biz_type, sysUniqueNo, discount_name, loan_amount};
				if (biz_type == 8) prams = {siteUserId, enterpiseId, saleId, brandName, brandId, carTypeName, carTypeId, carName, carId, logo, energy, transaction_price, down_method, down_ratio, down_amount, periods: parseInt(periods), repayment, biz_type, loan_amount};
				if (biz_type == 9) prams = {additionalRate, additionalAmt, siteUserId, enterpiseId, saleId, brandName, brandId, carTypeName, carTypeId, carName, carId, logo, energy, transaction_price, down_method, down_ratio, down_amount, periods: parseInt(periods), repayment, biz_type, loan_amount};
				this._createOrder(prams, this.header);
			},
			// -----------------------网络请求--------------------------
			_createOrder(prams, header) {
				uni.showLoading();
				createOrder(JSON.stringify(prams), header).then(res => {
					const data = res.data;
					if(data.resultCode != "0000") {
						uni.showToast({
							icon: 'none',
							title: res.data.resultMsg,
							duration: 3000
						});
						uni.hideLoading();
					}else {
						const orderId = data.data.orderId;
						let unfinished = prams;
						unfinished["orderId"] = orderId;
						uni.setStorage({
							key: 'unfinished',
							data: unfinished,
							success: function() {
								uni.hideLoading();
								uni.navigateTo({ url: '../personal-information/personal-information?orderId='+orderId });
							}
						});
					}
				})
			},
			_getOrderLinshiByid(prams, header) {
				let _this = this;
				uni.showLoading();
				getOrderLinshiByid(JSON.stringify(prams), header).then(res => {
					const data = res.data;
					if(data.resultCode != "0000") {
						uni.showToast({
							icon: 'none',
							title: res.data.resultMsg,
							duration: 3000
						});
						uni.hideLoading();
					}else {
						let searchData = data.data.orderLinshi; 
						let gouchedaiData = {...this.gouchedaiData, ...searchData}
						this.gouchedaiData = gouchedaiData
						app.globalData.gouchedaiData = gouchedaiData;
						uni.hideLoading();
					}
				})
			},
		}
	}
</script>

<style>
	@import url("./confirmation.css");
</style>
